package com.qlslylq.ad.example.activity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;

import com.qlslylq.ad.example.R;
import com.qlslylq.ad.example.constant.KeyConst;
import com.qlslylq.ad.sdk.core.listener.RewardAdListener;
import com.qlslylq.ad.sdk.core.loader.RewardAdLoader;
import com.qlslylq.ad.sdk.core.rsp.AdError;
import com.qlslylq.ad.sdk.util.GsonUtils;
import com.qlslylq.ad.sdk.util.Log;

/**
 * 激励广告测试页<br/>
 */
public class RewardAdTestMainActivity extends BaseActivity {

    private RewardAdLoader loader;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reward_ad_test_main);
    }

    protected void initView() {
        setTitle("激励广告测试");
    }

    protected void initData() {
        initLoader();
    }

    protected void initListener() {

    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_0:
                reverseScreenOrientation();
                break;
            case R.id.btn_1:
                loader.load();
                break;
            case R.id.btn_2:
                loader.show();
                break;
            case R.id.btn_3:
                loader.loadAndShow();
                break;
            case R.id.btn_4:
                showToast("正在开发中~");
                break;
        }
    }

    private void initLoader() {
        if (loader == null) {
            loader = new RewardAdLoader(this, KeyConst.JH_REWARD_POS_ID, new RewardAdListener() {

                public void onAdShow() {
                    Log.i("onAdShow");
                }

                public void onAdShowError(AdError error) {
                    Log.i("onAdShowError：" + GsonUtils.gsonString(error));
                    showToast("onAdShowError");
                }

                public void onReward() {
                    Log.i("onReward");
                    showToast("onReward");
                }

                public void onAdComplete() {
                    Log.i("onAdComplete");
                    showToast("onAdComplete");
                }

                public void onAdDismiss() {
                    Log.i("onAdDismiss");
                    showToast("onAdDismiss");
                }

                public void onAdClick() {
                    Log.i("onAdClick");
                    showToast("onAdClick");
                }
            });
        }
    }

    /**
     * 横竖屏切换<br/>
     */
    private void reverseScreenOrientation() {
        setRequestedOrientation(
                getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                        ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                        : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}